{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for a binary tree node.\n",
    "# class TreeNode:\n",
    "#     def __init__(self, x):\n",
    "#         self.val = x\n",
    "#         self.left = None\n",
    "#         self.right = None\n",
    "\n",
    "class Solution:\n",
    "    def isSymmetric(self, root: TreeNode) -> bool:\n",
    "        if root is None:\n",
    "            return True\n",
    "        node_list = [root]\n",
    "        while node_list:\n",
    "            val_list = []\n",
    "            next_level = []\n",
    "            for node in node_list:\n",
    "                if node:\n",
    "                    val_list.append(node.val)\n",
    "                    next_level.append(node.left)\n",
    "                    next_level.append(node.right)                    \n",
    "                else:\n",
    "                    val_list.append(None)\n",
    "            for i in range(len(val_list)//2):\n",
    "                if val_list[i] != val_list[-(i+1)]:\n",
    "                    return False\n",
    "            del node_list[:]\n",
    "            del val_list[:]\n",
    "            node_list = next_level\n",
    "        return True"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
